package eclipse.lib.graphics.primitives;
import com.sun.opengl.util.texture.Texture;
/**
 * The GLTile class acts as an Object for basic Tiles. It is really just a static sprite with the dimensions 32x32.
 *
 */
public class GLTile extends GLQuad
{
	private float u1, u2, v1, v2;
	/**
	 * Sets the texture of the Tile
	 * @param texture Texture that the tile uses
	 */
	public void setTexture(Texture texture)
	{
		GLPolygon polygon = getPolygon();
		polygon.setTexture(texture);
	}
	/**
	 * Sets the Tile image as a sub-image of the tile's texture.
	 * @param xSource Left-most position of the tile's pixels
	 * @param ySource Top-most position of the tile'pixels
	 */
	public void setTile(int xSource, int ySource)
	{
		GLPolygon polygon = this.getPolygon();
		u1 = (xSource * 32f) / polygon.getTexture().getWidth();
		v1 = (ySource * 32f) / polygon.getTexture().getHeight();
		u2 = (xSource * 32f + 32f) / polygon.getTexture().getWidth();
		v2 = (ySource * 32f + 32f) / polygon.getTexture().getHeight();
		polygon.setUV(0, u1, v1);
		polygon.setUV(1, u2, v1);
		polygon.setUV(2, u2, v2);
		polygon.setUV(3, u1, v2);
	}
}
